package cn.vcjf.weapp.api.setting.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.vcjf.weapp.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import cn.vcjf.weapp.api.setting.entity.Adv;
import cn.vcjf.weapp.api.setting.service.AdvService;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-25
 */
@Controller
@RequestMapping("/setting/adv")
public class AdvController {
     @Resource
     private AdvService  advService;

     @RequestMapping("/addAdv")
     @ResponseBody
     public TableResult addAdv(Adv adv){
         adv.preInsert();
         boolean b = advService.insert(adv);
         return TableResult.Result(b);
     }

     @RequestMapping("/updateAdv")
     @ResponseBody
     public TableResult updateAdv(Adv adv){
         adv.preUpdate();
        boolean b = advService.updateById(adv);
         return TableResult.Result(b);
     }

     @RequestMapping("/findAdvOne")
     @ResponseBody
     public TableResult findAdvOne(Adv adv){

        EntityWrapper<Adv> wrapper = adv.getQueryWrapper();

        Adv result = advService.selectOne(wrapper);

		return TableResult.OKResult(result);
     }
    //获取app首页广告轮播图
     @RequestMapping("/findAdvList")
     @ResponseBody
     public TableResult findAdvList(Adv adv){

        EntityWrapper<Adv> wrapper = new EntityWrapper<>();

        wrapper.eq("sysUserId",adv.getSysUserId());
        //广告位置(类型)APP首页轮播,PC端首页轮播,PC端分类广告
        wrapper.eq("type",1);
        //上线/下线
        wrapper.eq("status",1);

        wrapper.orderBy("sort");

        Page<Adv> page = adv.getPageInfo();

        page = advService.selectPage(page,wrapper);

		return TableResult.OKResult(page);

     }

     @RequestMapping("/deleteAdv")
     @ResponseBody
     public TableResult deleteAdv(Adv adv){
        adv.preUpdate();
        boolean b = advService.deleteById(adv.getId());
        return TableResult.Result(b);
     }

}
